import {apiGetUser} from "@/api/user";
import {getToken, removeToken} from "@/utils/auth";
import {strUtils} from "@/utils/lwUtils";

export function setAplus(t1,t2) {
    let zwlog;
    apiGetUser().then(res => {
        let isLogin = !strUtils.isEmpty(res.code, res.msg);
        if (!isLogin) {
            console.log("当前未登录，埋点信息不加入用户信息");
        } else {
            console.log("当前已登录，埋点信息加入用户信息(" + res.data.userId + "/" + res.data.userName + ")");
        }

        zwlog = new ZwLog({miniAppId: "2001700221", miniAppName: '台州市企业登记档案查询'});
        zwlog.onReady(function () {
            zwlog.sendPV({
                miniAppId: "2001700221",
                miniAppName: '台州市企业登记档案查询',
                log_status: isLogin ? "02" : "01",  //01:未登录/02:单点登录
                t2: ((new Date().getTime() - t1) / 1000) + "s", //'页面启动到加载完成的时间',
                t0: t2 + "s",  //'页面启动到页面响应完成的时间',
                pageId: 'eraq-zlb',
                pageName: '台州市企业登记档案查询',
                _user_id: isLogin ? res.data.userId : '',
                _user_nick: isLogin ? res.data.userName : "",
            });
            zwlog.record('yourTrackerEventCode', 'CLK', {
                Test1: "test params via helh",
            });
            let { metaInfo } = zwlog; // SDK元配置的当前设置
        });
    }).catch(err => {
        removeToken();
        console.log("获取用户信息错误，埋点失败");
    });
}

